﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Tireguit.Nmon.Parser.NmonTables
{
    public  class TablesDictionnary:SortedDictionary<string,string>
    {
        public TablesDictionnary()
        {
            Add("AAA", "[AAA_Table]");
            Add("BBBB", "[BBBB_Table]");
            Add("BBBC", "[BBBC_Table]");
            Add("BBBD", "[BBBD_Table]");
            Add("BBBP", "[BBBP_Table]");
            Add("CPU_ALL", "[CPUALL_Table]");
            Add("CPU", "[CPU_Table]");
            Add("MEM", "[MEM_Table]");
            Add("MEMUSE", "[MEMUSE_Table]");
            Add("PAGE", "[PAGE_Table]");
            Add("PROC", "[PROC_Table]");
            Add("FILE", "[FILE_Table]");
            Add("TOP", "[TOP_Table]");
            Add("NET", "[NET_Table]");
            Add("NETPACKET", "[NETPACKET_Table]");
            Add("DISKBUSY", "[DISKBUSY_Table]");
            Add("DISKREAD", "[DISKREAD_Table]");
            Add("DISKWRITE", "[DISKWRITE_Table]");
            Add("DISKXFER", "[DISKXFER_Table]");
            Add("DISKBSIZE", "[DISKBSIZE_Table]");
            Add("IOADAPT", "[IOADAPT_Table]");
            Add("JFSFILE", "[JFSFILE_Table]");
            Add("JFSINODE", "[JFSINODE_Table]");
            Add("ZZZZ", "[ZZZZ_Table]");
            Add("NETERROR", "[NETERROR_Table]");
        }
        static TablesDictionnary _instance=null;
        public static TablesDictionnary Instance
        {
            get
            {
                if (_instance==null)
                {
                    _instance = new TablesDictionnary();
                }
                return _instance;
            }
        }
        public static List<IDbCommand> GetTruncateCommand(IDbConnection connection)
        {
            try
            {
                List<IDbCommand> listcde = new List<IDbCommand>();
                System.Data.SqlServerCe.SqlCeConnection conn=connection as System.Data.SqlServerCe.SqlCeConnection;
                if (conn!=null)
                {
                    foreach (var elem in Instance)
                    {
                        IDbCommand cde = connection.CreateCommand();
                        cde.CommandText = "DELETE FROM " + elem.Value;
                        listcde.Add(cde);
                    }
                    return listcde;
                }
                foreach (var elem in Instance)
                {
                    IDbCommand cde = connection.CreateCommand();
                    cde.CommandText = "TRUNCATE TABLE " + elem.Value;
                    listcde.Add(cde);
                }
                return listcde;
            }
            catch (System.Exception ex)
            {
                throw ex;
            }

        }
    }
}
